package com.wyh.strategy.g3impl;

import com.wyh.domain.po.g3po.G3Contractitem;
import com.wyh.mapper.g3mapper.FormulaMapper;
import com.wyh.strategy.g3strategy.CalculationBillAmount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

@Component
@Order(1)
//三表类计费
public class ThreeTableBill implements CalculationBillAmount {
    @Autowired
    private FormulaMapper formulaMapper;
    @Autowired
    private Environment environment;
    @Override
    public Double calculationBillAmount(G3Contractitem g3Contractitem) {
        //先查询出sql语句头
        String sqlHeader = formulaMapper.selectFormulaById(g3Contractitem.getFormula());
        //从配置文件读出sql语句
        String formula = environment.getProperty(sqlHeader);
        if (formula != null) {
            Double dosage = formulaMapper.selectThreeTablePriceById(g3Contractitem,formula);
            return dosage;
        }

        return 0.0;

    }
}
